/*
Copyright 2009 Lawren Quigley-Jones

   preferences-assistant.js is part of Preopoly.

   Preopoly is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Preopoly is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Preopoly.  If not, see <http://www.gnu.org/licenses/>.

   Contact Lawren Quigley-Jones with questions or bugs:
   lawrenqj@gmail.com
*/

function PreferencesAssistant() {
}

PreferencesAssistant.prototype.setup = function() {
try {
  this.updateMoneySection();

  var standardToggle = {
    property: "value",
    trueValue: 'true',
    falseValue: 'false',
  };

  step = 5;
  var standardRateSlider = {
    modelProperty: 'value',
    minValue: 0,
    maxValue: 100/step,
    round: true,
    updateInterval: 0.5
  }

		// numPlayers
  this.controller.get("NumPlayersText").update(prefs.numPlayers);
  this.controller.setupWidget("NumPlayers", { 
    modelProperty: 'value',
    minValue: 2,
    maxValue: playerArray.length,
    round: true,
    updateInterval: 0.5
  },
  this.numPlayersModel = {
    value: prefs.numPlayers,
    disabled: false
  }
  );
  Mojo.Event.listen(this.controller.get('NumPlayers'), Mojo.Event.propertyChange, this.numPlayersUpdate.bindAsEventListener(this));

		// computer offers trades
  this.controller.get("OfferTradesText").update(prefs.computerOffersTrades);
  this.controller.setupWidget('OfferTrades', {
    modelProperty: 'value',
    minValue: 0,
    maxValue: 10,
    round: true,
    updateInterval: 0.5
  },
  this.offerTradesModel = {
     value: prefs.computerOffersTrades
  });
  this.offerTradesModel.value = prefs.computerOffersTrades;
  Mojo.Event.listen(this.controller.get('OfferTrades'), Mojo.Event.propertyChange, this.offerTradesUpdate.bindAsEventListener(this));

		// doubleOnGo
  this.controller.setupWidget('DoubleOnGo', standardToggle,
    this.doubleOnGoModel = { 
      value: prefs.doubleOnGo
    });
  Mojo.Event.listen(this.controller.get('DoubleOnGo'), Mojo.Event.propertyChange, this.doubleOnGoToggle.bind(this));

		// disable endturn button
  this.controller.setupWidget('DisableEndTurnButton', standardToggle,
    this.disableEndTurnModel = {
      value: prefs.disableEndTurn
    });
  Mojo.Event.listen(this.controller.get('DisableEndTurnButton'), Mojo.Event.propertyChange, this.disableEndTurnToggle.bind(this));

		// rent in jail
  this.controller.setupWidget('RentInJail', standardToggle,
    this.rentInJailModel = {
      value: prefs.rentInJail
    });
  Mojo.Event.listen(this.controller.get('RentInJail'), Mojo.Event.propertyChange, this.rentInJailToggle.bind(this));

		// pay to free parking
  this.controller.setupWidget('PayToFreeParking', standardToggle,
    this.payToFreeParkingModel = {
      value: prefs.payToFreeParking
    });
  Mojo.Event.listen(this.controller.get('PayToFreeParking'), Mojo.Event.propertyChange, this.payToFreeParkingToggle.bind(this));

		// show player's movements
  this.controller.setupWidget('ShowSteps', standardToggle,
    this.showStepsModel = {
      value: prefs.showSteps
    });
  Mojo.Event.listen(this.controller.get('ShowSteps'), Mojo.Event.propertyChange, this.showStepsToggle.bind(this));

		// show player's movements
  this.controller.setupWidget('bankMode', standardToggle,
    this.bankModeModel = {
      value: prefs.bankMode
    });
  Mojo.Event.listen(this.controller.get('bankMode'), Mojo.Event.propertyChange, this.bankModeToggle.bind(this));

		// Show Property on Purchase
  this.controller.setupWidget('displayPropertyCards', standardToggle,
    this.displayPropertyCardsModel = {
      value: prefs.displayPropertyCards
    });
  Mojo.Event.listen(this.controller.get('displayPropertyCards'), Mojo.Event.propertyChange, this.displayPropertyCardsToggle.bind(this));

		// remove bankrupt pieces
  this.controller.setupWidget('RemoveBankruptPieces', standardToggle,
    this.removeBankruptPiecesModel = {
      value: prefs.removeBankruptPieces
    });
  Mojo.Event.listen(this.controller.get('RemoveBankruptPieces'), Mojo.Event.propertyChange, this.removeBankruptPiecesToggle.bind(this));

		//complexDebts
  this.controller.setupWidget('complexDebts', standardToggle,
    this.complexDebtsModel = {
      value: prefs.complexDebts
    });
  Mojo.Event.listen(this.controller.get('complexDebts'), Mojo.Event.propertyChange, this.complexDebtsToggle.bind(this));

  /*
		// maxDebt
  this.controller.get("maxDebtText").update(prefs.maxDebt);
  this.controller.setupWidget("maxDebt", { 
    modelProperty: 'value',
    minValue: 0,
    maxValue: 5000 / 100,
    round: true,
    updateInterval: 0.5
  },
  this.maxDebtModel = { value: prefs.maxDebt / 100 }
  );
  Mojo.Event.listen(this.controller.get('maxDebt'), Mojo.Event.propertyChange, this.maxDebtUpdate.bindAsEventListener(this));
  */

		// starting money
  this.controller.get("StartMoneyText").update(prefs.startMoney);
  this.controller.setupWidget("StartMoney", { 
      modelProperty: 'value',
      minValue: 0,
      maxValue: 30,
      round: true,
      updateInterval: 0.5
    },
    this.startMoneyModel = {
      value: prefs.startMoney / 100,
      disabled: false
    }
  );
  Mojo.Event.listen(this.controller.get('StartMoney'), Mojo.Event.propertyChange, this.startMoneyUpdate.bindAsEventListener(this));

		// houseBuyBackRate
  this.controller.get("houseBuyBackRateText").update( prefs.houseBuyBackRate * 100 );
  this.controller.setupWidget("houseBuyBackRate", standardRateSlider,
    this.houseBuyBackRateModel = {
      value: ( prefs.houseBuyBackRate * 100/step )
    });
  Mojo.Event.listen(this.controller.get('houseBuyBackRate'), Mojo.Event.propertyChange, this.houseBuyBackRateUpdate.bindAsEventListener(this));

		// mortgageRate
  this.controller.get("mortgageRateText").update( prefs.mortgageRate * 100 );
  this.controller.setupWidget("mortgageRate", standardRateSlider,
    this.mortgageRateModel = {
      value: prefs.mortgageRate * 100/step
    });
  Mojo.Event.listen(this.controller.get('mortgageRate'), Mojo.Event.propertyChange, this.mortgageRateUpdate.bindAsEventListener(this));

		// mortgageValue
  this.controller.get("mortgageValueText").update( prefs.mortgageValue * 100 );
  this.controller.setupWidget("mortgageValue", standardRateSlider,
    this.mortgageValueModel = {
      value: prefs.mortgageValue * 100/step
    });
  Mojo.Event.listen(this.controller.get('mortgageValue'), Mojo.Event.propertyChange, this.mortgageValueUpdate.bindAsEventListener(this));

		// moneyDown
  this.controller.get("moneyDownText").update( prefs.moneyDown * 100 );
  this.controller.setupWidget("moneyDown", standardRateSlider,
    this.moneyDownModel = {
      value: prefs.moneyDown * 100/step
    });
  Mojo.Event.listen(this.controller.get('moneyDown'), Mojo.Event.propertyChange, this.moneyDownUpdate.bindAsEventListener(this));

		// minimumPayments
  this.controller.get("minimumPaymentsText").update( prefs.minimumPayments * 100 );
  this.controller.setupWidget("minimumPayments", standardRateSlider, 
    this.minimumPaymentsModel = {
      value: prefs.minimumPayments * 100/step
    });
  Mojo.Event.listen(this.controller.get('minimumPayments'), Mojo.Event.propertyChange, this.minimumPaymentsUpdate.bindAsEventListener(this));

		// interestRate
  this.controller.get("interestRateText").update( prefs.interestRate * 100 );
  this.controller.setupWidget("interestRate", standardRateSlider,
    this.interestRateModel = {
      value: prefs.interestRate * 100/step
    });
  Mojo.Event.listen(this.controller.get('interestRate'), Mojo.Event.propertyChange, this.interestRateUpdate.bindAsEventListener(this));

		// PlayerNames
  var playerlist = [];
  for ( var i=0; i<playerArray.length; i++ )
    playerlist.push({ label: playerArray[i].playerName, value: i });
  this.controller.setupWidget('PlayerNames',
    {
      label: 'change player names',
      choices: playerlist,
      modelProperty: 'value'
    },
    this.playerNamesModel = {
    }
  ); 
  Mojo.Event.listen(this.controller.get('PlayerNames'), Mojo.Event.propertyChange, this.newPlayerSelected.bindAsEventListener(this));

		// player name text field
  var defaultTextField = {
      multiline: false,
      growWidth: true,
      enterSubmits: true,
      modifierState: Mojo.Widget.capsLock,
      focusMode: Mojo.Widget.focusSelectMode
  };

  this.controller.setupWidget('PlayerNameID', defaultTextField, this.playerNameIDModel = {
   disabled: true
  }); 
  Mojo.Event.listen(this.controller.get('PlayerNameID'), Mojo.Event.propertyChange, this.playerNameUpdated.bindAsEventListener(this));

		// property name text field
  this.controller.setupWidget('PropertyNameID', defaultTextField, this.propertyNameIDModel = {
   disabled: true
  });
  Mojo.Event.listen(this.controller.get('PropertyNameID'), Mojo.Event.propertyChange, this.propertyNameUpdated.bindAsEventListener(this));

		// playerType
  this.controller.setupWidget('PlayerTypeID',
    {
      trueValue: 'computer',
      trueLabel: 'on',
      falseValue: 'human',
      falseLabel: 'off'
    },
    this.playerTypeModel = {
      value: 'human',
      disabled: false
    }); 
  Mojo.Event.listen(this.controller.get('PlayerTypeID'), Mojo.Event.propertyChange, this.playerTypeUpdated.bindAsEventListener(this));

		// Property Names
  var propertylist = [];
  for ( var i=0; i<propertyArray.length; i++ )
    propertylist.push({ label: propertyArray[i][propertyName], value: i });
  this.controller.setupWidget('PropertyNames',
    {
    label: 'change property names',
    choices: propertylist,
    modelProperty: 'value'
    },
    this.propertyNamesModel = {
    }
  ); 
  Mojo.Event.listen(this.controller.get('PropertyNames'), Mojo.Event.propertyChange, this.newPropertySelected.bindAsEventListener(this));


		// preferences button
  this.controller.setupWidget('ResetButton',{},
    this.preferencesButtonModel = {
      buttonLabel : 'Defaults',
      buttonClass : '',
      disable : false
    });
  Mojo.Event.listen(this.controller.get('ResetButton'), Mojo.Event.tap, this.resetPrefs.bind(this));

} catch(x) { if ( debug ) Mojo.Log.error('Exception in preferences setup: ' + x); }
}

PreferencesAssistant.prototype.resetPrefs = function(event){
try {
  clearPrefs();
  savePrefsCookie();
  this.updateMoneySection();

  this.doubleOnGoModel.value = prefs.doubleOnGo;
  this.controller.modelChanged(this.doubleOnGoModel, this);
  this.disableEndTurnModel.value = prefs.disableEndTurn;
  this.controller.modelChanged(this.disableEndTurnModel, this);
  this.rentInJailModel.value = prefs.rentInJail;
  this.controller.modelChanged(this.rentInJailModel, this);
  this.payToFreeParkingModel.value = prefs.payToFreeParking;
  this.controller.modelChanged(this.payToFreeParkingModel, this);
  this.offerTradesModel.value = prefs.computerOffersTrades;
  this.controller.modelChanged(this.offerTradesModel, this);
  this.controller.get("OfferTradesText").update(prefs.computerOffersTrades);
  this.showStepsModel.value = prefs.showSteps;
  this.controller.modelChanged(this.showStepsModel, this);
  this.bankModeModel.value = prefs.bankMode;
  this.controller.modelChanged(this.bankModeModel, this);
  this.removeBankruptPiecesModel.value = prefs.removeBankruptPieces;
  this.controller.modelChanged(this.removeBankruptPiecesModel, this);
  this.displayPropertyCardsModel.value = prefs.displayPropertyCards;
  this.controller.modelChanged(this.displayPropertyCardsModel, this);
  this.complexDebtsModel.value = prefs.complexDebts;
  this.controller.modelChanged(this.complexDebtsModel, this);
  this.numPlayersModel.value = prefs.numPlayers;
  this.controller.modelChanged(this.numPlayersModel, this);

  this.startMoneyModel.value = prefs.startMoney / 100;
  this.controller.modelChanged(this.startMoneyModel, this);
  this.controller.get("StartMoneyText").update(prefs.startMoney);
  //this.maxDebtModel.value = prefs.maxDebt / 100;
  //this.controller.modelChanged(this.maxDebtModel, this);
  //this.controller.get("maxDebtText").update(prefs.maxDebt);

  this.houseBuyBackRateModel.value = prefs.houseBuyBackRate * 100/step;
  this.controller.modelChanged(this.houseBuyBackRateModel, this);
  this.controller.get("houseBuyBackRateText").update( this.houseBuyBackRateModel.value * step );
  this.mortgageRateModel.value = prefs.mortgageRate * 100/step;
  this.controller.modelChanged(this.mortgageRateModel, this);
  this.controller.get("mortgageRateText").update( this.mortgageRateModel.value * step );
  this.mortgageValueModel.value = prefs.mortgageValue * 100/step;
  this.controller.modelChanged(this.mortgageValueModel, this);
  this.controller.get("mortgageValueText").update( this.mortgageValueModel.value * step );
  this.moneyDownModel.value = prefs.moneyDown * 100/step;
  this.controller.modelChanged(this.moneyDownModel, this);
  this.controller.get("moneyDownText").update( this.moneyDownModel.value * step );
  this.minimumPaymentsModel.value = prefs.minimumPayments * 100/step;
  this.controller.modelChanged(this.minimumPaymentsModel, this);
  this.controller.get("minimumPaymentsText").update( this.minimumPaymentsModel.value * step );
  this.interestRateModel.value = prefs.interestRate * 100/step;
  this.controller.modelChanged(this.interestRateModel, this);
  this.controller.get("interestRateText").update( this.interestRateModel.value * step );

  playerArray = [];
  propertyArray = [];
  resetPlayerNames();
  setPropertyGlobal();

  this.playerNamesCookie = new Mojo.Model.Cookie("playerNamesCookie");
  this.playerNamesCookie.remove();
  this.playerNamesCookie.put(playerArray);

  this.propertyArrayCookie = new Mojo.Model.Cookie("propertyArrayCookie");
  this.propertyArrayCookie.remove();
  tmparray = [];
  for ( var i=0; i<=39; i++ )
    tmparray[i] = propertyArray[i][propertyName];
  this.propertyArrayCookie.put(tmparray);

  clearDynamicObjects();

		// reset player list
  var playerlist = [];
  for ( var i=0; i<playerArray.length; i++ )
    playerlist.push({ label: playerArray[i].playerName, value: i });
  this.playerNamesModel.choices = playerlist;
  this.controller.modelChanged(this.playerNamesModel, this);
  this.playerNameIDModel.value = "";
  this.controller.modelChanged(this.playerNameIDModel, this);

		// reset property list
  var propertylist = [];
  for ( var i=0; i<propertyArray.length; i++ )
    propertylist.push({ label: propertyArray[i][propertyName], value: i });
  this.propertyNamesModel.choices = propertylist;
  this.controller.modelChanged(this.propertyNamesModel, this);
  this.propertyNameIDModel.value = "";
  this.controller.modelChanged(this.propertyNameIDModel, this);

} catch(x) { if ( debug ) Mojo.Log.error('Exception in reset prefs: ' + x); }
}

/*
PreferencesAssistant.prototype.maxDebtUpdate = function(event){
  prefs.maxDebt = this.maxDebtModel.value * 100;
  this.controller.get("maxDebtText").update(prefs.maxDebt);
  savePrefsCookie();
}
*/

PreferencesAssistant.prototype.numPlayersUpdate = function(event){
  prefs.numPlayers = this.numPlayersModel.value;
  this.controller.get("NumPlayersText").update(prefs.numPlayers);
  savePrefsCookie();
  clearDynamicObjects();
}

PreferencesAssistant.prototype.startMoneyUpdate = function(event){
  prefs.startMoney = this.startMoneyModel.value * 100;
  this.controller.get("StartMoneyText").update(prefs.startMoney);
  savePrefsCookie();
}

PreferencesAssistant.prototype.houseBuyBackRateUpdate = function(event){
  prefs.houseBuyBackRate = this.houseBuyBackRateModel.value / (100/step);
  this.controller.get("houseBuyBackRateText").update( this.houseBuyBackRateModel.value * step );
  savePrefsCookie();
}

PreferencesAssistant.prototype.mortgageRateUpdate = function(event){
  this.controller.get("mortgageRateText").update( this.mortgageRateModel.value * step );
  prefs.mortgageRate = this.mortgageRateModel.value / (100/step);
  savePrefsCookie();
}

PreferencesAssistant.prototype.mortgageValueUpdate = function(event){
  this.controller.get("mortgageValueText").update( this.mortgageValueModel.value * step );
  prefs.mortgageValue = this.mortgageValueModel.value / (100/step);
  savePrefsCookie();
}

PreferencesAssistant.prototype.moneyDownUpdate = function(event){
  this.controller.get("moneyDownText").update( this.moneyDownModel.value * step );
  prefs.moneyDown = this.moneyDownModel.value / (100/step);
  savePrefsCookie();
}

PreferencesAssistant.prototype.minimumPaymentsUpdate = function(event){
  this.controller.get("minimumPaymentsText").update( this.minimumPaymentsModel.value * step );
  prefs.minimumPayments = this.minimumPaymentsModel.value / (100/step);
  savePrefsCookie();
}

PreferencesAssistant.prototype.interestRateUpdate = function(event){
  this.controller.get("interestRateText").update( this.interestRateModel.value * step );
  prefs.interestRate = this.interestRateModel.value / (100/step);
  savePrefsCookie();
}

PreferencesAssistant.prototype.newPlayerSelected = function(event){
try {
		// update the player type selector
  this.playerTypeModel.value = playerArray[ this.playerNamesModel.value ].playerType;
  this.controller.modelChanged(this.playerTypeModel, this);

		// update the player name text field
  this.playerNameIDModel.value = playerArray[this.playerNamesModel.value].playerName;
  this.playerNameIDModel.disabled = false;
  this.controller.modelChanged(this.playerNameIDModel, this);
} catch(x) { if ( debug ) Mojo.Log.error('Exception in new player selected: ' + x); }
}

PreferencesAssistant.prototype.playerTypeUpdated = function(event){
  playerArray[ this.playerNamesModel.value ].playerType = this.playerTypeModel.value;

		// store in both the player settings cookie and the dynamic player cookie
  this.playerNamesCookie = new Mojo.Model.Cookie("playerNamesCookie");
  this.playerNamesCookie.put(playerArray);

  this.playerCookie = new Mojo.Model.Cookie("playerCookie");
  this.playerCookie.put(playerArray);
}

PreferencesAssistant.prototype.playerNameUpdated = function(event){
try {
  playerArray[this.playerNamesModel.value].playerName = this.playerNameIDModel.value;

  var playerlist = [];
  for ( var i=0; i<playerArray.length; i++ )
    playerlist.push({ label: playerArray[i].playerName, value: i });
  this.playerNamesModel.choices = playerlist;
  this.controller.modelChanged(this.playerNamesModel, this);

		// store in both the player settings cookie and the dynamic player cookie
  this.playerNamesCookie = new Mojo.Model.Cookie("playerNamesCookie");
  this.playerNamesCookie.put(playerArray);

  this.playerCookie = new Mojo.Model.Cookie("playerCookie");
  this.playerCookie.put(playerArray);

} catch(x) { if ( debug ) Mojo.Log.error('Exception in name update: ' + x); }
}

PreferencesAssistant.prototype.newPropertySelected = function(event){
try {
  this.propertyNameIDModel.value = propertyArray[this.propertyNamesModel.value][propertyName];
  this.propertyNameIDModel.disabled = false;
  this.controller.modelChanged(this.propertyNameIDModel, this);
} catch(x) { if ( debug ) Mojo.Log.error('Exception in new property selected: ' + x); }
}

PreferencesAssistant.prototype.propertyNameUpdated = function(event){
try {
  propertyArray[this.propertyNamesModel.value][propertyName] = this.propertyNameIDModel.value;

  var propertylist = [];
  var tmparray = [];
  for ( var i=0; i<propertyArray.length; i++ ) {
    propertylist.push({ label: propertyArray[i][propertyName], value: i });
    tmparray[i] = propertyArray[i][propertyName];
  }
  this.propertyNamesModel.choices = propertylist;
  this.controller.modelChanged(this.propertyNamesModel, this);

  this.propertyArrayCookie = new Mojo.Model.Cookie("propertyArrayCookie");
  this.propertyArrayCookie.put(tmparray);

} catch(x) { if ( debug ) Mojo.Log.error('Exception in property name updated: ' + x); }
}

PreferencesAssistant.prototype.offerTradesUpdate = function(event) {
  prefs.computerOffersTrades = this.offerTradesModel.value;
  this.controller.get("OfferTradesText").update(prefs.computerOffersTrades);
  savePrefsCookie();
}

PreferencesAssistant.prototype.showStepsToggle = function(event) {
  prefs.showSteps = this.showStepsModel.value;
  savePrefsCookie();
}

PreferencesAssistant.prototype.bankModeToggle = function(event) {
  prefs.bankMode = this.bankModeModel.value;
  savePrefsCookie();
  clearDynamicObjects();
}

PreferencesAssistant.prototype.displayPropertyCardsToggle = function(event) {
  prefs.displayPropertyCards = this.displayPropertyCardsModel.value;
  savePrefsCookie();
}

PreferencesAssistant.prototype.complexDebtsToggle = function(event) {
  prefs.complexDebts = this.complexDebtsModel.value;
  this.updateMoneySection();
  savePrefsCookie();
  clearDynamicObjects();
}

PreferencesAssistant.prototype.updateMoneySection = function() {
  if ( prefs.complexDebts == 'true' ) {
    //this.controller.get('debtDiv').style.height = "200px";
    this.controller.get('debtDiv').style.height = "150px";
    this.controller.get('standardDebtPrefs').style.visibility = "hidden";
    this.controller.get('complexDebtPrefs').style.visibility = "visible";
  }
  else {
    this.controller.get('debtDiv').style.height = "150px";
    this.controller.get('standardDebtPrefs').style.visibility = "visible";
    this.controller.get('complexDebtPrefs').style.visibility = "hidden";
  }
}

PreferencesAssistant.prototype.removeBankruptPiecesToggle = function(event) {
  prefs.removeBankruptPieces = this.removeBankruptPiecesModel.value;
  savePrefsCookie();
}

PreferencesAssistant.prototype.rentInJailToggle = function(event) {
  prefs.rentInJail = this.rentInJailModel.value;
  savePrefsCookie();
}

PreferencesAssistant.prototype.payToFreeParkingToggle = function(event) {
  prefs.payToFreeParking = this.payToFreeParkingModel.value;
  savePrefsCookie();
}

PreferencesAssistant.prototype.disableEndTurnToggle = function(event) {
try {
  prefs.disableEndTurn = this.disableEndTurnModel.value;
  //this.disableEndTurnCookie = new Mojo.Model.Cookie("disableEndTurnCookie");
  //this.disableEndTurnCookie.put(disableEndTurn);
  savePrefsCookie();
} catch(x) { if ( debug ) Mojo.Log.error('Exception in disable end turn button toggle toggle: ' + x); }
}

PreferencesAssistant.prototype.doubleOnGoToggle = function(event){
try {
  prefs.doubleOnGo = this.doubleOnGoModel.value;
  savePrefsCookie();
} catch(x) { if ( debug ) Mojo.Log.error('Exception in double on go toggle: ' + x); }
}

PreferencesAssistant.prototype.activate = function(event) {
}

PreferencesAssistant.prototype.deactivate = function(event) {
}

PreferencesAssistant.prototype.cleanup = function(event) {
  Mojo.Event.stopListening(this.controller.get('DoubleOnGo'), Mojo.Event.propertyChange, this.doubleOnGoToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('DisableEndTurnButton'), Mojo.Event.propertyChange, this.disableEndTurnToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('RentInJail'), Mojo.Event.propertyChange, this.rentInJailToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('PayToFreeParking'), Mojo.Event.propertyChange, this.payToFreeParkingToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('OfferTrades'), Mojo.Event.propertyChange, this.offerTradesUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('ShowSteps'), Mojo.Event.propertyChange, this.showStepsToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('bankMode'), Mojo.Event.propertyChange, this.bankModeToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('RemoveBankruptPieces'), Mojo.Event.propertyChange, this.removeBankruptPiecesToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('displayPropertyCards'), Mojo.Event.propertyChange, this.displayPropertyCardsToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('complexDebts'), Mojo.Event.propertyChange, this.complexDebtsToggle.bind(this));
  Mojo.Event.stopListening(this.controller.get('NumPlayers'), Mojo.Event.propertyChange, this.numPlayersUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('houseBuyBackRate'), Mojo.Event.propertyChange, this.houseBuyBackRateUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('mortgageRate'), Mojo.Event.propertyChange, this.mortgageRateUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('mortgageValue'), Mojo.Event.propertyChange, this.mortgageValueUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('moneyDown'), Mojo.Event.propertyChange, this.moneyDownUpdate.bindAsEventListener(this));
  //Mojo.Event.stopListening(this.controller.get('maxDebt'), Mojo.Event.propertyChange, this.maxDebtUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('minimumPayments'), Mojo.Event.propertyChange, this.minimumPaymentsUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('interestRate'), Mojo.Event.propertyChange, this.interestRateUpdate.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('StartMoney'), Mojo.Event.propertyChange, this.startMoneyUpdate.bindAsEventListener(this));

  Mojo.Event.stopListening(this.controller.get('PlayerNames'), Mojo.Event.propertyChange, this.newPlayerSelected.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('PlayerNameID'), Mojo.Event.propertyChange, this.playerNameUpdated.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('PlayerTypeID'), Mojo.Event.propertyChange, this.playerTypeUpdated.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('PropertyNames'), Mojo.Event.propertyChange, this.newPropertySelected.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('PropertyNameID'), Mojo.Event.propertyChange, this.propertyNameUpdated.bindAsEventListener(this));
  Mojo.Event.stopListening(this.controller.get('ResetButton'), Mojo.Event.tap, this.resetPrefs.bind(this));
}
